﻿using UnityEngine;
using System.Collections;

public class Main : MonoBehaviour
{
    CheckVersion mCheckVision; // 版本检测

    // Use this for initialization
	void Start ()
    {
        Logger.CreateInstance();
        AssetsLoad.Clear();

        mCheckVision = new CheckVersion();
        mCheckVision.Start(CheckVersionEnd);

        CheckVersionEnd();

//         new AssetsDependencies();
//         ResDownLoad.me.loadRes(ResourcesPath.RemotePath + "AssetsDependencies.XML", LoadDepXML, null);
	}

    void CheckVersionEnd()
    {
        // 版本检测完成

        // 开始加载场景
        new AssetsDependencies();

#if UNITY_EDITOR
        ResourceDown.Instance.Load("file://" + ResourcesPath.LocalPath + "AssetsDependencies.XML", LoadDepXML, null);
#endif
#if (UNITY_ANDROID || UNITY_IPHONE) && (!UNITY_EDITOR)
        ResourceDown.Instance.Load("file://" + ResourcesPath.LocalPath + "AssetsDependencies.XML", LoadDepXML, null);
#endif
    }

    void LoadDepXML(WWW www, object p)
    {
        AssetsDependencies.mInstance.LoadXML(www.bytes);

        // 加载完成之后，开始加载场景资源
        AssetsLoad.Load("Root_prefab_Dep.assetbunld", LoadSceneEnd, null);
    }

    void LoadSceneEnd(GameObject obj, object p)
    {
        ConsoleSelf.me.addText("LoadSceneEnd");

        Terrain terrain = Object.FindObjectOfType<Terrain>();
        if (terrain != null)
        {
            ConsoleSelf.me.addText("name:{0}", terrain.name);
            if (terrain.terrainData != null)
            {
                ConsoleSelf.me.addText("terrain.terrainData != null");
            }
            else
            {
                ConsoleSelf.me.addText("terrain.terrainData == null");
            }

            terrain.Flush();
        }
    }
}
